import { APP, STORAGE_KEY } from '../types'

export default {
  namespaced: true,
  state: {
    // 系统主题
    theme: uni.getStorageSync(STORAGE_KEY.THEME) || 'light',
    // 系统配置
    config: {
      // 是否开启tabbar
      hasTabBar: true
    }
  },
  mutations: {
    // 设置主题
    [APP.SET_THEME](state, theme) {
      state.theme = theme
      uni.setStorageSync(STORAGE_KEY.THEME, theme)
    },
    // 设置系统配置
    [APP.SET_CONFIG](state, config) {
      state.config = {
        ...state.config,
        ...config
      }
    }
  },
  actions: {
    // 切换主题
    toggleTheme({ commit, state }) {
      const theme = state.theme === 'light' ? 'dark' : 'light'
      commit(APP.SET_THEME, theme)
    }
  },
  getters: {
    theme: state => state.theme,
    config: state => state.config
  }
} 